# Pydantic 自带很多 Buff，能嵌套，能 IDE 提示补全，能用尽用，除了 BaseModel，还有 HttpUrl 等

from fastapi import FastAPI
from pydantic import BaseModel, HttpUrl

app = FastAPI()


class Image(BaseModel):
    url: HttpUrl # 用 Pydantic 的 HttpUrl 来定义
    name: str


class Item(BaseModel):
    name: str
    description: str | None = None
    price: float
    tax: float | None = None
    tags: set[str] = set() # 不重复的列表用 set
    images: list[Image] | None = None # 可重复的列表用 list


class Offer(BaseModel):
    name: str
    description: str | None = None
    price: float
    items: list[Item]


@app.post("/offers/")
async def create_offer(offer: Offer):
    return offer
